package com.qianbao.qianbaobusiness.ui.invoice.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianbao.qianbaobusiness.R;

/**
 * @author: Routee
 * @date 2018/6/12
 * @mail wangc4@qianbaocard.com
 * ------------1.本类由Routee开发,阅读、修改时请勿随意修改代码排版格式后提交到git。
 * ------------2.阅读本类时，发现不合理请及时指正.
 * ------------3.如需在本类内部进行修改,请先联系Routee,若未经同意修改此类后造成损失本人概不负责。
 */

public class InvalidInvoiceDialog extends Dialog {

    public static final int INVALID_PROCESS_STATE = 0;
    public static final int INVALID_SUCCESS_STATE = 1;
    public static final int INVALID_FAIL_STATE    = 2;
    private int                  mCurrentState;
    private View                 mView;
    private ConfirmClickListener mListener;
    private ImageView            mIvState;
    private TextView             mTvState;
    private TextView             mTvNotify;
    private TextView             mTvConfirm;

    public InvalidInvoiceDialog(@NonNull Context context) {
        this(context, R.style.customDialogTheme);
    }

    public InvalidInvoiceDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    private void initView() {
        setCanceledOnTouchOutside(false);
        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.dialog_invaliding_invoice, null);
        addContentView(mView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        mIvState = mView.findViewById(R.id.iv_state);
        mTvState = mView.findViewById(R.id.tv_state);
        mTvNotify = mView.findViewById(R.id.tv_notify);
        mTvConfirm = mView.findViewById(R.id.tv_confirm);
        mTvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mListener != null) {
                    mListener.click(mCurrentState);
                }
            }
        });
    }

    public void setState(int state) {
        mCurrentState = state;
        switch (state) {
            case INVALID_PROCESS_STATE:
                mTvState.setText("正在作废，请稍等");
                mIvState.setImageResource(R.drawable.icon_transaction_detail_processing);
                mTvNotify.setVisibility(View.GONE);
                mTvConfirm.setVisibility(View.GONE);
                break;
            case INVALID_SUCCESS_STATE:
                mTvState.setText("作废成功");
                mIvState.setImageResource(R.drawable.icon_transaction_detail_success);
                mTvNotify.setVisibility(View.VISIBLE);
                mTvConfirm.setVisibility(View.VISIBLE);
                break;
            case INVALID_FAIL_STATE:
                mTvState.setText("作废失败");
                mIvState.setImageResource(R.drawable.icon_transaction_detail_fail);
                mTvNotify.setVisibility(View.GONE);
                mTvConfirm.setVisibility(View.VISIBLE);
                break;
            default:
                break;
        }
    }

    public interface ConfirmClickListener {
        void click(int state);
    }

    public void setClickListener(ConfirmClickListener listener) {
        mListener = listener;
    }
}

